﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Runtime.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace WebApplication1.TagHelpers
{
    // You may need to install the Microsoft.AspNetCore.Razor.Runtime package into your project
    //[HtmlTargetElement("tag-name")]
    [HtmlTargetElement("EmailReplace")]
    public class EmailReplaceTagHelper : TagHelper
    {

        //过滤条件
        [HtmlAttributeName("condition")]
        public bool Condition { get; set; }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {

            if (Condition)
            {
                output.TagName = "a";
                output.TagMode = TagMode.StartTagAndEndTag; //默认情况,有开始和结束标签
                //output.TagMode = TagMode.StartTagOnly;//只有开始标签
                //output.TagMode = TagMode.SelfClosing;//自关闭标签

                output.Attributes.SetAttribute("href", "http://www.baidu.com");
                output.Content.SetContent("百度");
            }
            else
            {
                //代表什么内容都没有
                output.SuppressOutput();//抑制输出
            }

        }
    }
}
